package 数据库连接池;


import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class DruidTest {

    @Test
    public void getConnection() throws Exception {
        //创建一个配置文件对象
        Properties pros=new Properties();
        //通过ClassLoader类的getSystemClassLoader()方法，再调用getResourceAsStream()去读取配置文件,返回一个读取指定文件的输入流;
        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("Druid.properties");
        //加载配置文件
        pros.load(is);
        //创建一个数据库连接池
        DataSource dataSource = DruidDataSourceFactory.createDataSource(pros);
        //通过连接池获取一个连接
        Connection connection = dataSource.getConnection();
        //打印连接
        System.out.println(connection);


    }
}
